package com.glamour.hlcity.component.framework.common;


import com.glamour.hlcity.common.enums.ErrorCodeEnum;

/**
 * Framework模块内部异常类
 * 
 * @author zhaoxing.liuzx
 */
public class FrameworkException extends RuntimeException {

	private static final long serialVersionUID = -3526723747394933728L;
	private static final String DEFAULT_MESSAGE_PREFIX = "Error Code : ";
    private String              errorCode;
    private ErrorCodeEnum           errorCodeEnum;

    public FrameworkException() {
        this(ErrorCodeEnum.SYS_ERROR, "", null);
    }


    public FrameworkException(String errCode) {
        this(errCode, "", null);
    }


    public FrameworkException(Throwable cause) {
        this(ErrorCodeEnum.SYS_ERROR, "", cause);
    }


    public FrameworkException(String errCode, String message) {
        this(errCode, message, null);
    }

    public FrameworkException(String errCode, Throwable cause) {
        this(errCode, "", cause);
    }


    public FrameworkException(String errCode, String message, Throwable cause) {
        super(DEFAULT_MESSAGE_PREFIX + errCode + "[" + message + "]", cause);
        this.errorCode = errCode;
    }

    public FrameworkException(ErrorCodeEnum errCode) {
        this(errCode, "", null);
    }

    public FrameworkException(ErrorCodeEnum errCode, String message) {
        this(errCode, message, null);
    }

    public FrameworkException(ErrorCodeEnum errCode, Throwable cause) {
        this(errCode, "", cause);
    }

    public FrameworkException(ErrorCodeEnum errCode, String message, Throwable cause) {
        super(DEFAULT_MESSAGE_PREFIX + errCode.getCode() + "[" + errCode.getMessage() + "]"
                + message, cause);
        this.errorCodeEnum = errCode;
    }

    /**
     * @return Returns the errorCode.
     */
    public String getErrCode() {
        if (errorCode != null) {
            return errorCode;
        }
        if (errorCodeEnum != null) {
            return errorCodeEnum.getCode();
        }
        return ErrorCodeEnum.SYS_ERROR.getCode();
    }
}
